<html>
<head><meta charset="utf-8"><title>WithOptConstParam · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html">WithOptConstParam</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215203445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203445">(Oct 31 2020 at 17:59)</a>:</h4>
<p>Today I <a href="https://github.com/rust-lang/rust/pull/78407#discussion_r515489890">saw "WithOptConstParam" for the first time</a>, and I have no idea what it does.^^ <span class="user-mention" data-user-id="216206">@lcnr</span> pointed me to <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.WithOptConstParam.html">the docs</a>, but unfortunately they do not help, as I do not understand any of what they say. :/  They seem to assume a lot of background knowledge that I lack.</p>
<blockquote>
<p>A DefId which is potentially bundled with its corresponding generic parameter in case did is a const argument.</p>
</blockquote>
<p>What does it mean for did to "be a const argument"? I though DefId refer to definitions, so things like <code>fn</code> or <code>struct</code> or so?<br>
As a consequence of this, the 2nd sentence makes no sense at all to me.</p>
<blockquote>
<p>Luckily we only need to deal with const arguments once we know their corresponding parameters. </p>
</blockquote>
<p>I am not sure what distinction the docs make between "arguments" and "parameters" here, I usually see them used as synonyms, so this is confusing.</p>



<a name="215203457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203457">(Oct 31 2020 at 17:59)</a>:</h4>
<p><span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="215203460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203460">(Oct 31 2020 at 17:59)</a>:</h4>
<p>I think a concrete example would really help^^</p>



<a name="215203530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203530">(Oct 31 2020 at 18:00)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="c1">//           ^ const param</span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span>::<span class="o">&lt;</span><span class="mi">7</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="c1">//    ^ const argument</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="215203643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203643">(Oct 31 2020 at 18:02)</a>:</h4>
<blockquote>
<p>I though DefId refer to definitions, so things like fn or struct or so?</p>
</blockquote>
<p>the <code>DefId</code> of a const argument refers to the anonymous constant used</p>



<a name="215203681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203681">(Oct 31 2020 at 18:03)</a>:</h4>
<p>re <code>param</code> and <code>argument</code>: I personally distinguish them as shown above, but have seen that this is not the case for everyone and may be incorrect</p>



<a name="215203689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203689">(Oct 31 2020 at 18:03)</a>:</h4>
<p>so if you have a better wording I would gladly use that instead <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="215203788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203788">(Oct 31 2020 at 18:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203681">said</a>:</p>
<blockquote>
<p>re <code>param</code> and <code>argument</code>: I personally distinguish them as shown above, but have seen that this is not the case for everyone and may be incorrect</p>
</blockquote>
<p>oh lol if anything I would have expected the exact opposite^^</p>



<a name="215203827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203827">(Oct 31 2020 at 18:06)</a>:</h4>
<p>but I might just be confused about this</p>



<a name="215203852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203852">(Oct 31 2020 at 18:07)</a>:</h4>
<p>I would probably try to use terminology along the lines of "definition" and "instance"... but also, just include an example in the docs</p>



<a name="215203856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203856">(Oct 31 2020 at 18:07)</a>:</h4>
<p>and not just an example for what param and argument are, but for the entire situation</p>



<a name="215203877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203877">(Oct 31 2020 at 18:07)</a>:</h4>
<p>that cycle you are talking about and how "lucky enough" somehow its not a problem if we do this "WithOptConstParam" dance</p>



<a name="215203892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203892">(Oct 31 2020 at 18:07)</a>:</h4>
<p>I have never even seen that cycle, so without an example there is no way I am going to understand what this is for^^</p>



<a name="215203937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203937">(Oct 31 2020 at 18:08)</a>:</h4>
<p>The docs already contain an example, but I will try add an explanation for this, are you up to review?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">A</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">B</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">u8</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"> </span><span class="mi">42</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">a</span><span class="p">.</span><span class="n">foo</span>::<span class="o">&lt;</span><span class="mi">7</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="215203958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203958">(Oct 31 2020 at 18:08)</a>:</h4>
<p>oh, the docs contain some code, but it has no connection to the text above</p>



<a name="215203959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203959">(Oct 31 2020 at 18:08)</a>:</h4>
<p>that I can see, anyway</p>



<a name="215203965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203965">(Oct 31 2020 at 18:08)</a>:</h4>
<p>probably the connection is clear if you already know all the answers :D</p>



<a name="215203970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203970">(Oct 31 2020 at 18:08)</a>:</h4>
<p>it always is <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="215203997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215203997">(Oct 31 2020 at 18:09)</a>:</h4>
<p>but to me it looks like a random unrelated piece of code.^^ where's the cycle? where's the WithOptConstParam? where's type_of(const_arg) depending on itself? where is "calling type_of(param_did) for these arguments"?</p>



<a name="215204025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204025">(Oct 31 2020 at 18:10)</a>:</h4>
<p>I have to leave now and to some cooking to avoid starvation, but I hope this was helpful feedback if you want to improve the docs :)</p>



<a name="215204072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204072">(Oct 31 2020 at 18:10)</a>:</h4>
<p>give me 10 minutes, will try to extend the struct docs and open a PR. enjoy your meal</p>



<a name="215204097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204097">(Oct 31 2020 at 18:11)</a>:</h4>
<p>and yes I am happy to give further feedback to changes you want to make :) I wouldnt call it a review though as I cannot judge if it makes any sense.^^</p>



<a name="215204103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204103">(Oct 31 2020 at 18:11)</a>:</h4>
<p>I give you 12h, won't be able to look into it before tomorrow anyway ;)</p>



<a name="215204179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204179">(Oct 31 2020 at 18:12)</a>:</h4>
<p>and thanks for not just making the compiler better but also working on docs! I know that can feel like wasted time compared to technical work, but it really helps a lot, and is the foundation for growing new contributors and for keeping this huge thing we are all building together maintainable :)</p>



<a name="215204209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215204209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215204209">(Oct 31 2020 at 18:13)</a>:</h4>
<p>(I should probably write more docs for the interpreter some day... <em>oops</em>)</p>



<a name="215206785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215206785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215206785">(Oct 31 2020 at 19:05)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/issues/78609">#78609</a>, feel free to point out anything unclear here even as someone who is not <span class="user-mention silent" data-user-id="120791">RalfJ</span></p>



<a name="215239704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215239704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215239704">(Nov 01 2020 at 11:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203788">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215203681">said</a>:</p>
<blockquote>
<p>re <code>param</code> and <code>argument</code>: I personally distinguish them as shown above, but have seen that this is not the case for everyone and may be incorrect</p>
</blockquote>
<p>oh lol if anything I would have expected the exact opposite^^</p>
</blockquote>
<p>These terms used to be used inconsistently, but we've since tried to make an effort to use them the way <span class="user-mention" data-user-id="216206">@lcnr</span> demonstrates, and I think they're fairly consistent internally and in diagnostics now.</p>



<a name="215951293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215951293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215951293">(Nov 07 2020 at 11:42)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> I see. I was more wondering if this is consistent with their use outside of rustc.</p>



<a name="215951802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215951802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215951802">(Nov 07 2020 at 11:56)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> so I am still confused by this, but I think I am getting closer... is this roughly right?<br>
In <a href="https://github.com/rust-lang/rust/pull/78609/files">your example</a>, we need to delay actually computing the value of the constant <code>7</code> until after the body is typechecked. (Won't that disable many interesting uses of const generics where the value influences dispatch, such as having separate implementations for <code>foo::&lt;false&gt;</code> and <code>foo::&lt;true&gt;</code>? Anyway.) For some reason, <code>type_of(const_arg)</code> triggers a computation of the value (?!?), so we cannot run that query (?). But somehow we already figured out the const param that the argument will instantiate, so we bundle the const_arg with the param so we can determine its type by looking at the type of the param... maybe?</p>
<p>I am confused about quite a few things, on top of the question marks above:</p>
<ul>
<li>I dont get why we cannot instead bundle the const_arg with the type (<code>WithOptTy</code> seems much simpler^^). somehow it seems important to indirect through the param.</li>
<li>I dont get how this avoids the cycle since we still need to figure out which const_param the argument will instantiate... I have the feeling the conceptual problem here is that typechecking the body and the const arg are two separate queries, but they can only really be done together, so really one query should compute both of these things.</li>
</ul>



<a name="215951952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215951952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215951952">(Nov 07 2020 at 12:01)</a>:</h4>
<blockquote>
<p>In your example, we need to delay actually computing the value of the constant 7 until after the body is typechecked. (Won't that disable many interesting uses of const generics where the value influences dispatch, such as having separate implementations for foo::&lt;false&gt; and foo::&lt;true&gt;? Anyway.)</p>
</blockquote>
<p>no, we have to work with <code>7</code> during typeck. You can already dispatch based on const values rn</p>



<a name="215952085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952085">(Nov 07 2020 at 12:05)</a>:</h4>
<p>maybe it helps to walk through how it works rn. Let me try this</p>



<a name="215952107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952107">(Nov 07 2020 at 12:06)</a>:</h4>
<p>I thought that's what you did in the PR? :D</p>



<a name="215952136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952136">(Nov 07 2020 at 12:06)</a>:</h4>
<p>Anyway I am afraid I have not much time... I can give feedback for a write-up someone made but I cannot spend half an hour interactively going through this. sorry.</p>



<a name="215952185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952185">(Nov 07 2020 at 12:08)</a>:</h4>
<p>unfortunate <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span> will think a bit more about this and then call it finished here</p>



<a name="215952256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952256">(Nov 07 2020 at 12:10)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="119009">@eddyb</span> I think using the type of the const param instead of its <code>DefId</code> also works and might be easier to understand. It might have an effect on incremental compilation though, so I am not sure if we want that. Anyways, I don't have the energy to experiment on this atm</p>



<a name="215952668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215952668">(Nov 07 2020 at 12:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215952256">said</a>:</p>
<blockquote>
<p>cc <span class="user-mention silent" data-user-id="119009">eddyb</span> I think using the type of the const param instead of its <code>DefId</code> also works and might be easier to understand. It might have an effect on incremental compilation though, so I am not sure if we want that. Anyways, I don't have the energy to experiment on this atm</p>
</blockquote>
<p>if that would at least be technically correct, this would be a new avenue for explaining the thing -- and maybe for a better name. random snippets of thought:<br>
"we need a way to pass around consts whose type we cannot query directly, but only through the parameter they instantiate"...  its less a const <em>with</em> a parameter than a const <em>for</em> a parameter. (<code>OptForConstParam</code>?).. "think of this as a const optionally bundled with its type (except we indirect the type through a DefId for $REASONS)"</p>



<a name="215953270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215953270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215953270">(Nov 07 2020 at 12:42)</a>:</h4>
<p>pushed another small change, is that a bit better?</p>



<a name="215953784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/WithOptConstParam/near/215953784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/WithOptConstParam.html#215953784">(Nov 07 2020 at 12:57)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>: yes, this is consistent with standard use (e.g. see <a href="https://blog.kotlin-academy.com/programmer-dictionary-parameter-vs-argument-type-parameter-vs-type-argument-b965d2cc6929">https://blog.kotlin-academy.com/programmer-dictionary-parameter-vs-argument-type-parameter-vs-type-argument-b965d2cc6929</a>).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>